home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 02 / monoicon.c < prev    next >
Text File  |  1991-01-09  |  4KB  |  151 lines

  1. #include "windows.h"
  2. #include "monoscrn.h"
  3. #include "gmhook.h"
  4.  
  5. #define WM_HOTEVENT     (WM_USER + 0x1000)
  6.  
  7. //function prototypes
  8. int      PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
  9.          BOOL   InitApplication(HANDLE);
  10.          BOOL   InitInstance(HANDLE, int);
  11. long FAR PASCAL MainWndProc(HWND, unsigned, WORD, LONG);
  12. void     PASCAL ConvertToRowCol(POINT *, POINT *, int, int);
  13.  
  14. HANDLE  hInst;
  15. BOOL    bOnMonoScreen = FALSE;
  16.  
  17. int PASCAL WinMain(HANDLE hInstance, 
  18.                    HANDLE hPrevInstance, 
  19.                    LPSTR lpCmdLine, int nCmdShow)
  20. {
  21.     MSG msg;
  22.  
  23.     if (!hPrevInstance) {
  24.         if (!InitApplication(hInstance))
  25.             return (FALSE);
  26.     } else return(FALSE);
  27.  
  28.     if (!InitInstance(hInstance, nCmdShow))
  29.         return (FALSE);
  30.  
  31.     while (GetMessage(&msg, NULL, NULL, NULL)) {
  32.         TranslateMessage(&msg);
  33.         DispatchMessage(&msg);
  34.     }
  35.     whRemoveGMHook();                     //REMOVE the GM Hook !!!
  36.     return (msg.wParam);
  37. }
  38.  
  39. BOOL InitApplication(HANDLE hInstance)
  40. {
  41.     WNDCLASS  wc;
  42.  
  43.     wc.style         = CS_DBLCLKS;
  44.     wc.lpfnWndProc   = MainWndProc;
  45.     wc.cbClsExtra    = 0;
  46.     wc.cbWndExtra    = 0;
  47.     wc.hInstance     = hInstance;
  48.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  49.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  50.     wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  51.     wc.lpszMenuName  = NULL;
  52.     wc.lpszClassName = "MonoIconClass";
  53.     return(RegisterClass(&wc));
  54. }
  55.  
  56. BOOL InitInstance(HANDLE hInstance, int nCmdShow)
  57. {
  58.     HWND    hwnd;
  59.  
  60.     hwnd = CreateWindow("MonoIconClass", "Gateway to Mono Monitor",
  61.                         WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
  62.                         CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,    
  63.                         NULL);
  64.     if (!hwnd)
  65.         return (FALSE);
  66.  
  67.     VioInit();
  68.     whInstallGMHook(hwnd, WM_HOTEVENT);         //INSTALL the GM Hook !!!
  69.     whEnableGMHook(TRUE);
  70.     ShowWindow(hwnd, SW_SHOWMINNOACTIVE);       //make window ICON
  71.     UpdateWindow(hwnd);
  72.     return(TRUE);
  73. }
  74.  
  75. long FAR PASCAL MainWndProc(HWND hwnd, unsigned msg, WORD wParam, LONG lParam)
  76. {
  77.     POINT ptTemp;
  78.     POINT ptMono;
  79.  
  80.     switch (msg) {
  81.         case WM_QUERYOPEN:
  82.             return(FALSE);                      //stay as an ICON
  83.  
  84.         case WM_DESTROY:
  85.             PostQuitMessage(0);
  86.             break;
  87.  
  88.         case WM_MOUSEMOVE:
  89.             if (bOnMonoScreen) {
  90.                 ptTemp.x = LOWORD(lParam);
  91.                 ptTemp.y = HIWORD(lParam);
  92.                 ClientToScreen(hwnd, &ptTemp);
  93.                 ConvertToRowCol(&ptTemp, &ptMono, 25, 80);
  94.                 VioMovePointer(ptMono.y, ptMono.x);
  95.             }
  96.             break;
  97.  
  98.         case WM_RBUTTONDBLCLK:
  99.             if (bOnMonoScreen) {
  100.                 whEnableGMHook(TRUE);
  101.                 ReleaseCapture();
  102.                 ShowCursor(TRUE);
  103.                 VioShowPointer(FALSE);
  104.                 bOnMonoScreen = FALSE;
  105.             }
  106.             break;
  107.  
  108.         case WM_HOTEVENT:
  109.             if (hwnd != GetActiveWindow())
  110.                 SetActiveWindow(hwnd);
  111.             whEnableGMHook(FALSE);
  112.             SetCapture(hwnd);
  113.             ShowCursor(FALSE);
  114.             VioShowPointer(TRUE);
  115.             bOnMonoScreen = TRUE;
  116.             break;
  117.  
  118.         default:
  119.             return (DefWindowProc(hwnd, msg, wParam, lParam));
  120.     }
  121.     return(NULL);
  122. }
  123.  
  124. void PASCAL ConvertToRowCol(POINT *ptScreen, POINT *ptMono, int iRow, int iCol)
  125. {
  126.     static BOOL bInit = 0;
  127.     static int  cxScreen = 0;
  128.     static int  cyScreen = 0;
  129.            int  iXConvFactor = 0;
  130.            int  iYConvFactor = 0;
  131.  
  132.     if (!bInit) {
  133.         cxScreen = GetSystemMetrics(SM_CXSCREEN);
  134.         cyScreen = GetSystemMetrics(SM_CYSCREEN);
  135.     }
  136.  
  137.     iXConvFactor = cxScreen / iCol;
  138.     iYConvFactor = cyScreen / iRow;
  139.  
  140.     (*ptMono).x = ptScreen->x / iXConvFactor;
  141.     (*ptMono).y = ptScreen->y / iYConvFactor;
  142.  
  143.     // fixup the math because were using INT instead of real numbers.
  144.     if (ptMono->x >= iCol)
  145.         ptMono->x = iCol-1;
  146.  
  147.     if (ptMono->y >= iRow)
  148.         ptMono->y = iRow-1;
  149. }
  150.  
  151.